
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>包装打印</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="author" content="yinqi">
<link href="static/css/bootstrap.min.css" rel="stylesheet">
<link href="static/css/materialdesignicons.min.css" rel="stylesheet">
<link href="static/css/style.min.css" rel="stylesheet">
</head>
  
<body>
<!--初始化生产线无数据模态框-->
      <div class="modal fade" data-backdrop="static" id="pLineModal_no" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" >选择产品并登录</h5>
            </div>
            
            <div class="modal-body">
              <select class="form-control" id="packing_select"  size="1">
                <option value="0">请选择要包装的产品</option>
                <option value="1">IBB产品--珠江路厂区</option>
                <option value="2">IBB产品--朝红路厂区</option>
                <option value="3">LBB产品--珠江路厂区</option>
                <option value="4">LBB产品--朝红路厂区</option>
              </select>
              <br>
              <input type="text" class="form-control" id="userid_input" placeholder="输入员工编号" value="WDIID02246"/>
              <br>
              <input type="password" class="form-control" id="userpassword_input" placeholder="输入包装人员密码" value="fujianxia"/>
              <br>
            </div>
            
            <div class="modal-footer">
              <button type="button" class="btn btn-primary" onclick="RunSurOK()">确定</button>
            </div>          
          </div>
        </div>
      </div>
    <!--退出程序模态框-->
      <div class="modal fade" data-backdrop="static"  id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="">退出程序(键盘Tab选中，Enter确认,Esc取消)</h5>
            </div>
            <div class="modal-body">
                <div class="form-group">
                  <div class="alert alert-danger" role="alert">警告：程序关闭后将不再监听，请确保生产线未在生产</div>
                  <label for="recipient-name" class="control-label">为了防止误关，请输入”close“关闭程序：</label>
                  <input type="text" class="form-control" id="password_input" value ="close" />
                </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
              <button type="button" class="btn btn-primary" id="ok_close_now">确定关闭程序</button>
            </div>
          </div>
        </div>
      </div>

  <!--头部信息-->     
  <nav class="navbar navbar-default">
    <div class="topbar">
      
      <div class="topbar-left">  
        <div class="lyear-aside-toggler">
          <span class="lyear-toggler-bar"></span>
          <span class="lyear-toggler-bar"></span>
          <span class="lyear-toggler-bar"></span>
        </div>
        <span class="navbar-page-title" id="navigation_bar_id">包装</span>
      </div>
      
      <ul class="topbar-right">
        <li class="dropdown dropdown-profile" onclick="close_windows()">
          <a href="javascript:void(0)" data-toggle="dropdown">
            <span>退出(Alt+Q)</span>
          </a>
        </li>

        <li class="dropdown dropdown-profile" id="min-bottom-taskbar">
          <span>&nbsp;&nbsp;&nbsp;&nbsp;|</span>
        </li>
        
        <li class="dropdown dropdown-profile">
          <span>&nbsp;&nbsp;&nbsp;&nbsp;|</span>
        </li>
        <li class="dropdown dropdown-profile" id="productionLineSetup">
          <a href="javascript:void(0)" data-toggle="dropdown">
            <span>设置产品并重登</span>
          </a>
        </li>
        
        <li class="dropdown dropdown-profile">
          <span>&nbsp;&nbsp;&nbsp;&nbsp;|</span>
        </li>
        <li class="dropdown dropdown-profile" onclick="cleanPackingInfo()">
          <a href="javascript:void(0)" data-toggle="dropdown">
            <span>清除当前正在包装</span>
          </a>
        </li>
        
        <!--<li class="dropdown dropdown-profile" >
          <span>&nbsp;&nbsp;&nbsp;&nbsp;|</span>
        </li>             
        <li class="dropdown dropdown-profile" onclick="selectErrorData()">
          <a href="javascript:void(0)" data-toggle="dropdown" >
            <span>错误操作记录</span>
          </a>
        </li> 
        
        <li class="dropdown dropdown-profile" >
          <span>&nbsp;&nbsp;&nbsp;&nbsp;|</span>
        </li>             
        <li class="dropdown dropdown-profile" onclick="">
          <a href="javascript:void(0)" data-toggle="dropdown" >
            <span>包装标签复打</span>
          </a>
        </li> -->
      </ul>
      
    </div>
  </nav>
  <!--End 头部信息-->
  <div class="container-fluid"> 
    
   
    <div class="row">
      <div class="col-lg-12">
        <div class="card" id="app">  
            
        </div>
      </div>
    </div>
    <!-- .row -->
  </div>
</body>

<script type="text/javascript" src="static/js/jquery.min.js"></script>
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="static/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="static/js/main.min.js"></script>

<!--消息提示-->
<script src="static/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="static/js/lightyear.js"></script>

<!--go语言后台 必须！-->
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript">

var closePasswordStr = "close";

var Packid_post = 0;

//页面载入完成
window.onload=function(){//do something
  //$('#pLineModal_no').modal('show');
  getNowPackagingStatus();
}

var gui = require('nw.gui');
var win = gui.Window.get();

//窗口关闭点击事件
$("#ok_close_now").click(function () {//窗口关闭
  lightyear.loading('show');

  var passwordInput = document.getElementById("password_input");
  if(passwordInput.value==closePasswordStr){
    win.close();
  }else{ 
    lightyear.notify('密码错误！', 'danger', 100);  
  }
  lightyear.loading('hide');
});



//显示关闭程序模态框
function close_windows(){
  $('#exampleModal').modal('show');
};

//退出快捷键
var option = {
  key : "Alt+Q",
  active : function() {
    $('#exampleModal').modal('show'); 
  },
  failed : function(msg) {
    console.log(msg);
  }
};
gui.App.registerGlobalHotKey(new gui.Shortcut(option));//--退出快捷键End

//重新设置包装信息 点击事件
$("#productionLineSetup").click(function () {//
  getNowPackagingStatus();
});

//查询包装状态
function getNowPackagingStatus(){
  lightyear.loading('show');
  $.ajax({
    type: 'POST',
    url: "http://localhost:8888/do.g",
    dataType : 'json',
    data:{dofunc:"getNowPackagingStatus"},
    success:function(data) { 
      Packid_post = data.Packid
      if(data.Packid==0&&data.Packnum==0&&data.Fbillno=="0"){
        //alert(JSON.stringify(data));
        $('#pLineModal_no').modal('show');
      }else{
        lightyear.notify('当前有包装箱还未完成包装！', 'danger', 100);  
      } 
      lightyear.loading('hide'); 
	  },
		error:function(data) {
			lightyear.notify('网络错误！', 'danger', 100);  
      lightyear.loading('hide');   
		}      
  });
}

//选择产品 和 登录确认
function RunSurOK(){
  var packing_select = document.getElementById("packing_select");
  var userid_input = document.getElementById("userid_input");
  var userpassword_input = document.getElementById("userpassword_input");
  
  //
  if (packing_select.value=="0"){
    lightyear.notify('请选择产品！', 'danger', 100);
    return;
  }
  if (userid_input.value == ""){
    lightyear.notify('员工编号为空！', 'danger', 100);
    return;
  }
  if (userpassword_input.value == ""){
    lightyear.notify('请输入密码！', 'danger', 100);
    return;
  }
  
  var productsName_s = "";
  if (packing_select.value=="1"){
    productsName_s = "IBB产品--珠江路厂区"
  }
  if (packing_select.value=="2"){
    productsName_s = "IBB产品--朝红路厂区"
  }
  if (packing_select.value=="3"){
    productsName_s = "LBB产品--珠江路厂区"
  }
  if (packing_select.value=="4"){
    productsName_s = "LBB产品--朝红路厂区"
  }
  
  lightyear.loading('show');
  $.ajax({
    type: 'POST',
    url: "http://localhost:8888/do.g",
    dataType : 'json',
    data:{dofunc:"doNowPackingData",productsType:packing_select.value,productsName: productsName_s,inputUserId:userid_input.value,password:userpassword_input.value},
    success:function(data) { 
      if (data.Errcode==0){
        $('#pLineModal_no').modal('hide');
      }
      if(data.Errcode==1){
        lightyear.notify(data.Errmsg, 'danger', 100);
      }   
      lightyear.loading('hide'); 
	  },
		error:function(data) {
			lightyear.notify('网络错误！', 'danger', 100);
      lightyear.loading('hide');   
		}      
  });
}

//查询错误日志
function selectErrorData(){
  lightyear.notify('查询错误日志！', 'danger', 100);  
}

function cleanPackingInfo(){
   if(confirm('确定要清除吗？')==true){
      lightyear.loading('show');
      $.ajax({
        type: 'POST',
        url: "http://localhost:8888/do.g",
        dataType : 'json',
        data:{dofunc:"doCleanPackingInfo",packid_post:Packid_post},
        success:function(data) { 
          if(data.Errcode==0){
            lightyear.notify('当前正在包装信息清除成功！', 'success', 3000);
          }else{
            lightyear.notify('当前正在包装信息清除失败！', 'danger', 100); 
          } 
          lightyear.loading('hide'); 
    	  },
    		error:function(data) {
    			lightyear.notify('网络错误！', 'danger', 100);  
          lightyear.loading('hide');   
    		}      
      });
   }  
}

</script>
</html>